package com.wtc.homework;

import java.lang.reflect.Array;
import java.util.Arrays;
import java.util.Comparator;

/**
 * @author 马可
 * @version 1.0
 * String翻转
 * 2023/5/26
 * IntelliJ IDEA
 */
public class Homework08 {
    public static void main(String[] args) {
        String str = "abcdef";
        System.out.println(reverse(str, 0, 4));
    }
    public static String reverse(String str, int start, int end) {
        String substring = str.substring(start, end);
        char[] arr = substring.toCharArray();
        char[] newArr = new char[arr.length];
        for (int length = arr.length - 1; length >= 0; length--) {
            newArr[(arr.length - 1) - length] = arr[length];
        }
        String s = String.valueOf(newArr);
        StringBuffer stringBuffer = new StringBuffer(str);
        StringBuffer replace = stringBuffer.replace(start, end, s);
        return String.valueOf(replace);

    }
}

